package org.codesketch.flamingo

import org.codesketch.flamingo.Snapshot;
import org.codesketch.flamingo.domain.Response

import grails.converters.JSON

class SnapshotController {
	
	SnapshotService snapshotService
	
    /*
	 * Redirects all the default call to all
	 */
	def index = {
		redirect(action: "list", params: params)
	}
	/**
	 * Retrieve all the {@link Snapshot} that matches the request.
	 * @return a list of {@link Snapshot} in a JSON format.
	 */
	def list() {
		Response<String> resp = new Response<String>();
		try {
			def snapshots = snapshotService.get(params.id.toLong())
			resp.setStatus(200)
			resp.setMessage("OK")
			resp.setData(snapshots)
		} catch (Exception e) {
			resp.setStatus(500)
			resp.setMessage(e.getMessage())
			resp.setData(null)
		}
		render resp as JSON
	}
}
